import router from '@/router';
import {
	service,
	request
} from '../../../../api/service.js';

export default {
	namespaced: true,
	state: {
		productDeliveryHeaderList: []
	},

	actions: {
		async LoadProductDelivery({
			dispatch
		}, {
			productDeliveryQuery = {},
			pageNumber = 1,
			pageSize = 10
		} = {}) {
			var response = await request({
				url: `MES/MESProductDelivery/QueryPage?
				childrencode=${productDeliveryQuery.childrencode}&
				projectcode=${productDeliveryQuery.projectcode}&
				projectname=${productDeliveryQuery.projectname}&
				equipmentName=${productDeliveryQuery.equipmentName}&
				floor=${productDeliveryQuery.floor}&
				libraryno=${productDeliveryQuery.libraryno}&
				pageNumber=${pageNumber}&		
				pageSize=${pageSize}
				`,
				method: 'get'
			});
			return response;
		},

		async LoadProjects({
			dispatch
		}, {
			type=null
		} = {}) {
			var response = await request({
				url: `MES/MESProductDelivery/GetProjects?type=${type}`,
				method: 'get'
			});
			if (response.status == 1) {
				return response.data;
			}
			return null;
		},

		async AddProductDeliveryDetail({
			dispatch
		}, {
			data
		} = {}) {
			var response = await request({
				url: 'MES/MESProductDelivery/AddDetail',
				method: 'post',
				data: data
			});
			return response;
		},

		async LoadChildrenToWebSelect({
			dispatch
		}, {
			type = null,
			projectCode = null
		} = {}) {
			var response = await request({
				url: `MES/MESProductDelivery/LoadChildrenToWebSelect?
				type=${type}&
				projectCode=${projectCode}
				`,
				method: 'get'
			});
			return response;
		},
		async AddProductDelivery({
			dispatch
		}, {
			data
		} = {}) {
			var response = await request({
				url: 'MES/MESProductDelivery/Add',
				method: 'post',
				data: data
			});
			return response;
		},
	},
	mutations: {
		get(state) {
			state.productDeliveryHeaderList = [{
					text: '项目号',
					value: 'check'
				},
				{
					text: '项目名称',
					value: 'needqty'
				},
				{
					text: '发货类型',
					value: 'materialcode'
				},
				{
					text: '楼层',
					value: 'materialname'
				},
				{
					text: '库号',
					value: 'materialspecification'
				},
			];
		}
	},

};
